package com.pig4cloud.pig.admin.util;

import com.pig4cloud.pig.admin.api.entity.MetaFieldEntity;
import com.pig4cloud.pig.admin.enums.BaseFieldType;

import java.util.ArrayList;
import java.util.List;


public class MetaFieldUtils {
	private static final List<String> FIELDS = new ArrayList<>() {{
		add("create_by");
		add("create_time");
		add("update_by");
		add("update_time");
		add("del_flag");
		add("process_instance_id");
	}};
	private static final String ID_FIELD_FLAG = "1";


	/***
	 * 判断是否是系统默认保留字段
	 * @param tMetaField
	 * @return
	 */
	public static Boolean isReservedField(MetaFieldEntity tMetaField) {
		return tMetaField.getDelFlag().equals(ID_FIELD_FLAG) || FIELDS.contains(tMetaField.getPhysicalName());
	}

	public static boolean isReservedField(String name) {
		return FIELDS.contains(name);
	}

	/***
	 * 获取默认字段FieldList
	 * @param entityCode
	 * @return
	 */
	public static List<MetaFieldEntity> getDefualtFieldList(Long entityId) {
		List<MetaFieldEntity> fieldList = new ArrayList<>();
		for (BaseFieldType baseType : BaseFieldType.values()) {
			MetaFieldEntity metaFieldEntity = new MetaFieldEntity();
			metaFieldEntity.setEntityId(entityId);
			metaFieldEntity.setUpdatable(baseType.getUpdatable());
			metaFieldEntity.setCreatable(baseType.getCreatable());
			metaFieldEntity.setNullable(baseType.getNullable());
			metaFieldEntity.setOrder(0L);
			metaFieldEntity.setSystemFieldFlag(baseType.getSystemFieldFlag());
			metaFieldEntity.setName(baseType.getName());
			metaFieldEntity.setLabel(baseType.getLabel());
			metaFieldEntity.setType(baseType.getType());
			metaFieldEntity.setPhysicalName(baseType.getLabel());
			fieldList.add(metaFieldEntity);
		}
		return fieldList;

	}

	public static List<MetaFieldEntity> getDefualtTreeFieldList(Integer entityCode) {
		List<MetaFieldEntity> fieldList = new ArrayList<>();
//		fieldList.add(new TMetaField("0000002-" + UUID.randomUUID().toString().replace("-", ""),
//				entityCode, "label", "标签", "label", "input", 0, 1, 1, 0, 0, 0, 0, "", "varchar(255)"));
//		fieldList.add(new TMetaField("0000002-" + UUID.randomUUID().toString().replace("-", ""),
//				entityCode, "code", "编码", "code", "input", 0, 1, 1, 0, 0, 0, 0, "", "varchar(255)"));
//		fieldList.add(new TMetaField("0000002-" + UUID.randomUUID().toString().replace("-", ""),
//				entityCode, "parentId", "父节id", "parentId", "input", 0, 1, 1, 0, 0, 0, 0, "", "int"));
		return fieldList;
	}
}
